<?php 
/**
 * eBay Label Printing Program Myaccount Controller 
 * This is the controller customer handlling staff
 * @package  eBayLabelPrinter
 * @category Controller
 * @author   Norman Dong <norman.dong@hotmail.com>
 * @version  Initial
 * @copyright LeadCasket.com
 * @link     www.leadcasket.com
 * @license  Commercial
 */
define ("TEMP_USER_GROUP", 0);

class MyaccountController extends Zend_Controller_Action
{
	
    public function init(){
    /**
	 *
	 *
	 */    
	
	}

    public function indexAction(){
	
		echo "Myaccount";	
    
	}
	
	/**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */
	public function quicksignupAction(){
		
		//return array();	
		$quickSignUpform = new Form_Quicksignup();
		$this->view->form = $quickSignUpform;
		$this->view->errflag = 0;
		
		//if Form posted 
		if($this->getRequest()->isPost()){
			
			$formData = $this->getRequest()->getPost();
			
				if($quickSignUpform->isValid($formData)){
		//create account ,first get form data			
					$userNameSeller  = $quickSignUpform->getValue('username_seller');
					$userEmailSeller = $quickSignUpform->getValue('user_email_seller');
					$senderName = $quickSignUpform->getValue('name_sender'); 
		            $unzipPassword = $quickSignUpform->getValue('unzip_password'); 
		//check if already registered 
					$seller = new Model_DbTable_Sellers_Seller();
					
					if(!$seller->checkUniqueSellerName($userNameSeller)){
							$this->view->errflag = 1; //errormessage = "User Name has been Taken,please use another one";
							}
					elseif(!$seller->checkUniqueSeller($userNameSeller,$userEmailSeller)){
							$this->view->errflag = 2; //errormessage = 	 "User Name has been Taken,please use another one";				
							}	
		//Two Unique tests passsed,this should be new user 				
					else{   
						   $passWdHandler = new Model_Handlers_Passwordhandler();
						   //generate one time uniqueID 
						   $uniqueIdSeller =  $passWdHandler->generateUniqueId();
						   $tempPassword = $passWdHandler->generatePassword();
						   $passWordSeller = $passWdHandler->generateHashPassword($tempPassword,$uniId);
						   //
						   unset($passWdHandler);
		//try to add this New Seller				   
						   if(!$seller->addSeller($userNameSeller,$userEmailSeller,$uniqueIdSeller,$passWordSeller,$unzipPassword,TEMP_USER_GROUP)){
							   $this->view->errflag = 3; //errormessage = 	 "Add User Failed";	
							   }
						   $idSeller = $seller->getSellerId($userNameSeller);
						   
						   $senderName = $form->getValue('name_sender'); 
						   $addrLine1 = $form->getValue('line1_seller_addr');
						   $addrLine2 =  $form->getValue('line2_seller_addr');
						   $addrCity =  $form->getValue('city_seller_addr');
						   $addrState =  $form->getValue('state_seller_addr');
						   $addrCountry =  $form->getValue('country_seller_addr');
						   $addrPostCode =  $form->getValue('postcode_seller_addr');
						   $addrShortLine1 =  $form->getValue('shortform_line1_addr'); 
						   $addrShortLine2 =  $form->getValue('shortform_line2_addr');       
		//after add in get seller ID ,then add the address
						   if($idSeller){
						   		$sellerAddr = new Model_DbTable_Selleraddress();
								
						   		if(!$sellerAddr->addSellerAddress($idSeller,$senderName,$addrLine1,$addrLine2,$addrCity,$addrState,$addrCountry,$addrPostCode,$addrShortLine1,$addrShortLine2)){
									$this->view->errflag = 5; //errormessage = 	 "Add Address Fail";	
									}
						   		unset($sellerAddr);
								}
						   else{
							   	$this->view->errflag = 4; //errormessage = 	 "Seller Id Not Found";		
									}		
							}	
					}
					
			}
		
		//setup the user type to temp 
		//add a new address 
		//goto My account Home page 			
		}
	/**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */
	public function normalsignupAction(){
		
		$normalSignUpform = new Form_Normalsignup();
		$this->view->form = $normalSignUpform;
		}		
	/**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */
	public function closeAccountAction(){
		echo "Close Myaccount";
		//return array();	
		}		
	/**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */		
   public function upgradeaccountAction(){
	   
	   }
	 /**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */		 	
   public function addaddressAction(){
	   
	   } 	   
	 /**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */		 	
   public function updateaddressAction(){
	   
	   }  
	 /**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */		 	
   public function deleteaddressAction(){
	   
	   }
	 /**
	 *  This is the Demo Action Function , I do not know what to put here
	 * So here goes some rubbish
	 * @param int $a  The first parameter
	 * @param string $b - The second one 
	 * @return array   for input 
	 */		 	
   public function deleteaddress2Action(){
	   
	   }	   
   	    	   		
}
?>